<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><html:text name="sys.name" /></title> 
<link rel="stylesheet" href="<%=WEBPATH%>/themes/dafault/xtree.css" type="text/css">
<script type="text/javascript" src="<%=WEBPATH%>/scripts/jquery/jquery.js"></script> 

<script type="text/javascript" src="<%=WEBPATH%>/scripts/xtree/xtree.js"></script>
<script type="text/javascript" src="<%=WEBPATH%>/scripts/xtree/xmlextras.js"></script>
<script type="text/javascript" src="<%=WEBPATH%>/scripts/xtree/xloadtree.js"></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/DepartAction.js?id=<%=generate%>'></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/DepartBean.js?id=<%=generate%>'></script>
</head>
<body>
<table width="100%" bordercolor="#000000" cellspacing="0" cellpadding="0" border="0" align="center">
	<tr>
		<td width="100" height="500" valign="top">
		<div style="padding-left: 5px;">
			<script type="text/javascript" charset="UTF-8">
					webFXTreeConfig.rootIcon		= "<%=WEBPATH%>/images/xloadtree/page_white_magnify.gif";
					webFXTreeConfig.openRootIcon	= "<%=WEBPATH%>/images/xloadtree/page_white_magnify.gif";
					webFXTreeConfig.folderIcon		= "<%=WEBPATH%>/images/xloadtree/folder.png";
					webFXTreeConfig.openFolderIcon	= "<%=WEBPATH%>/images/xloadtree/openfolder.png";
					webFXTreeConfig.fileIcon		= "<%=WEBPATH%>/images/xloadtree/page_white_gear.gif";
					webFXTreeConfig.lMinusIcon		= "<%=WEBPATH%>/images/xloadtree/Lminus.png";
					webFXTreeConfig.lPlusIcon		= "<%=WEBPATH%>/images/xloadtree/Lplus.png";
					webFXTreeConfig.tMinusIcon		= "<%=WEBPATH%>/images/xloadtree/Tminus.png";
					webFXTreeConfig.tPlusIcon		= "<%=WEBPATH%>/images/xloadtree/Tplus.png";
					webFXTreeConfig.iIcon			= "<%=WEBPATH%>/images/xloadtree/I.png";
					webFXTreeConfig.lIcon			= "<%=WEBPATH%>/images/xloadtree/L.png";
					webFXTreeConfig.tIcon			= "<%=WEBPATH%>/images/xloadtree/T.png";
					webFXTreeConfig.blankIcon		= "<%=WEBPATH%>/images/xloadtree/blank.png";
					var treeDict = new WebFXTree("部门",""); 
					<html:iterator value="departChildBeans" id="departChildBeans">
						<html:if test="child==0" >
							treeDict.add(new WebFXTreeItem("<html:property value="departName"/>","javascript:showCategory('<html:property value="id"/>')","","<%=WEBPATH%>/images/xloadtree/folder.png"));
						</html:if>
						<html:else>
							treeDict.add(new WebFXLoadTreeItem("<html:property value="departName"/>", "<%=WEBPATH%>/system/depart/child.crm?id=<html:property value="id"/>","javascript:showListAndTree('<html:property value="id"/>')"));
						</html:else>
							
					</html:iterator> 
					document.write(treeDict);
				</script></div>
		</td>
		<td width="80%" valign="top">
			<table class="detail" cellspacing="0" cellpadding="0" border="0" align="center">
				<tr>
					<td><html:text name="depart.departName"/><html:hidden id="id" name="id"/></td>
					<td><html:textfield   id="departName" name="departName" cssStyle="width:95%" /></td>
					<td><html:text name="depart.departManager"/><html:hidden id="departManagerId" name="departManagerId"/></td>
					<td><html:textfield   id="departManager" name="departManager" cssStyle="width:87%" /></td>
				</tr>
				<tr>
					<td><html:text name="depart.telNo"/><html:hidden id="parentId" name="parentId" value="1"/></td>
					<td><html:textfield   id="telNo" name="telNo" cssStyle="width:95%" /></td>
					<td><html:text name="depart.faxNo"/></td>
					<td><html:textfield   id="faxNo" name="faxNo" cssStyle="width:87%" /></td>
				</tr>
				<tr>
					<td><html:text name="depart.departDescn"/></td>
					<td colspan="3"><html:textarea  id="departDescn" name="departDescn" cssStyle="width:95%" cols="5" /></td>
				</tr>
				<tr>
					<td colspan="4" align="right">&nbsp;<input 
					id="saveBtn" name="saveBtn" type="button" 
					value=" <html:text name="button.save"></html:text> "
					style="width: 90px" onclick="javascript:saveRole();"></input> &nbsp; &nbsp; &nbsp;<input
					name="deleteBtn" id="deleteBtn" type="button"  
					value=" <html:text name="button.delete"></html:text> "
					style="width: 90px" onclick="javascript:delRole();"></input>&nbsp; &nbsp; &nbsp;<input
					name="backBtn" id="backBtn" type="button"  
					value=" <html:text name="button.back"></html:text> "
					style="width: 90px" onclick="javascript:backRole();"></input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<script type="text/javascript" charset="UTF-8">
	function showCategory(id){
		DepartAction.dwrView(id,updateData);
	}
	function updateData(data){
		jQuery('#id').val(data.id);
		jQuery('#departName').val(data.departName);
		jQuery('#departDescn').val(data.departDescn);
		jQuery('#departManagerId').val(data.departManagerId);
		jQuery('#departManager').val(data.departManager);
		jQuery('#telNo').val(data.telNo);
		jQuery('#faxNo').val(data.faxNo);
		jQuery('#parentId').val(data.parent.id);
		jQuery('#deleteBtn').show();
		jQuery('#backBtn').show();
		jQuery('#saveBtn').show();
	}
	function saveRole(){
		var parentBean={id:jQuery('#parentId').attr("value")};
		
		var DepartBean={
			id: jQuery('#id').attr("value"),
			departName: jQuery('#departName').attr("value"),
			departManager: jQuery('#departManager').attr("value"),
			departManagerId: jQuery('#departManagerId').attr("value"),
			telNo: jQuery('#telNo').attr("value"),
			faxNo: jQuery('#faxNo').attr("value"),
			departDescn: jQuery('#departDescn').attr("value"),
			parent:parentBean
		}
		/***alert(jQuery('#id').attr("value"));
		alert(jQuery('#departName').attr("value"));
		alert(jQuery('#departManager').attr("value"));
		alert(jQuery('#departManagerId').attr("value"));
		alert(jQuery('#telNo').attr("value"));
		alert(jQuery('#faxNo').attr("value"));
		alert(jQuery('#departDescn').attr("value"));
		alert(jQuery('#parentId').attr("value"));***/
		DepartAction.dwrSave(DepartBean,saveCallBack);
	}
	function saveCallBack(data){
		if(data=="success"){
			if(jQuery('#id').attr("value")==""){
				alert("<html:text name="entity.saved"/>"); 
			}else{
				alert("<html:text name="entity.updated"/>");  
			}
			window.location="<%=WEBPATH%>/system/depart/index.crm";
		}else{
			if(jQuery('#id').attr("value")==""){
				alert("<html:text name="entity.saved.error"/>");
			}else{
				alert("<html:text name="entity.updated.error"/>");
			}
		}		
	}
	function delRole(){
		var id=jQuery('#id').attr("value");
		DepartAction.dwrDelete(id,deleteCallBack);
	}
	function deleteCallBack(data){
		if(data=="success"){
			alert("<html:text name="entity.deleted"/>");
			window.location="<%=WEBPATH%>/system/depart/index.crm";
		}else{
			alert("<html:text name="entity.deleted.error"/>");
		}
	}
	function init(){
		jQuery('#id').val("");
		jQuery('#departName').val("");
		jQuery('#departManager').val("");
		jQuery('#departManagerId').val("");
		jQuery('#telNo').val("");
		jQuery('#faxNo').val("");
		jQuery('#parentId').val("1");
		jQuery('#departDescn').val("");
		jQuery('#deleteBtn').hide();
		jQuery('#backBtn').hide();
		jQuery('#saveBtn').show();
	}
	init();
	function backRole(){
		init();
	}
</script>
</body>
</html>